import { SocketClient } from "./socketClient/SocketClient";
import { WebSocketServeMain } from "./webSocketServe/WebSocketServeMain";

class Main {
    private webSocketServe: WebSocketServeMain;
    private socketClient: SocketClient;
    constructor() {
        // 端口号请自行修改
        const port = 3001;

        this.socketClient = new SocketClient();
        this.socketClient.setReceiveCallBack(this.onSockrtRecrive.bind(this))

        this.webSocketServe = new WebSocketServeMain(port, this.socketClient);
        this.webSocketServe.setRecriveCallBack(this.onWebSocketReceive.bind(this));
    }

    /**webSocket收到消息 */
    private onWebSocketReceive(data: ArrayBuffer) {
        console.log('上行数据', data);
        this.socketClient.onSend(data);
    }

    /**scocket收到消息 */
    private onSockrtRecrive(data: ArrayBuffer) {
        console.log('下行数据', data);
        this.webSocketServe.onSend(data);
    }
}
new Main();